<template>
  <div class="video">
    <div class="list" :style="{height:listHeight+'px'}" v-if="list && list.length>0">
      <div class="video-list" v-for="(item,index) in list" :id="'list_'+item.id"
           :style="{width:width+'px',height:height-20+'px'}" @click="selectItem(item.id)">
        <video :src="webCfg.api.url+':'+webCfg.api.fileSvrPort+'/'+item.videoPath" autoplay controls loop
               style="width: 100%; height: 100%; object-fit: cover;" type="video/mp4" v-if="item.videoPath"></video>
        <img :src="item.imagePath" alt="" style="width: 100%; height: 100%; object-fit: cover;" v-else>
        <p class="state">
          {{item['stateName']}}
          <span class="diyCheckBox"><span class="point"></span></span>
        </p>

      </div>
    </div>
    <div v-else style="color:#666; display: flex; align-items: center; justify-content: center" :style="{height:height*3+'px'}">
      查询结果为空！
    </div>
    <div class="bottom" :style="{height:bottomHeight+'px'}">
      <slot></slot>
    </div>
  </div>
</template>

<script>

  export default {
    name: "VideoList",
    components: {
    },
    props: {
      list: {
        default: [],
        type: Array
      }
    },
    data() {
      return {
        webCfg:WebCfg,
        width: 480,
        height: 270,
        listHeight: 500,
        bottomHeight: 200,
        videoCfg: {},

        panelShow: false,
        panelCfg: {},
        panelData:{},

        checkList: [],
        checkedList: []
      }
    },
    created() {
      this.initSize();
    },
    watch:{
        list(n,o){
         this.initSelect();
        }
    },
    methods: {
      initSize() {
        const W = window.screen.width, H = document.body.clientHeight;
        let headerHeight = 61;
        if (W <= 1400) {
          headerHeight = 51;
        }
        this.width = W * 0.75 / 4;
        this.height = this.width * 9 / 16;
        this.listHeight = (this.height - 20) * 4;
        this.videoCfg = {
          autoplay: false,
          controls: true,
          muted: true,
          width: this.width,
          height: this.height,
          // fluid: true,
        };
        this.bottomHeight = H - headerHeight - this.listHeight;
      },

      closePanel() {
        this.panelShow = false;
      },
      action(item) {
        this.panelCfg = item;
        this.panelShow = true;
      },

      selectItem(id) {
        const $dom = document.querySelector('#list_' + id);
        const index = this.checkedList.indexOf(id);
        if (index < 0) {
          this.checkedList.push(id);
          $dom.classList.add('active');

        } else {
          this.checkedList.splice(index, 1);
          $dom.classList.remove('active');
        }

        this.$parent.selectItem(this.checkedList)
      },

      initSelect(){
        this.checkedList.forEach(id=>{
          document.querySelector('#list_'+id).classList.remove('active');
        });
        this.checkedLis=[];
        this.checkedList.length=0;
      }
    }
  }
</script>

<style scoped lang="scss">
  .video {
    height: 100%;
    background-color: #000;

    .video-list {
      float: left;
      overflow: hidden;
      border: 1px solid #000;
      box-sizing: border-box;
      cursor: pointer;
      position: relative;

      .name {
        position: absolute;
        bottom: 0;
        left: 0;
        text-align: center;
        font-size: 14px;
        font-weight: 600;
        text-shadow: -1px -1px 1px #333, 1px 1px 1px #999;
      }

      .state {
        position: absolute;
        top: 0;
        right: 5px;
        text-align: center;
        font-size: 14px;
        font-weight: 600;
        color: #999;
        text-shadow: -1px -1px 1px #000, 1px 1px 1px #333;
      }
    }

    .bottom {
      display: flex;
      justify-content: center;
      align-items: center;
      background-color: #000;
    }

    .diyCheckBox {
      display: inline-block;
      height: 16px;
      width: 16px;
      top: 3px;
      background-color: #fff;
      text-align: center;
      border: 1px solid #888;
      padding: 2px;
      box-sizing: border-box;
      position: relative;

      .point {
        position: absolute;
        top: 2px;
        left: 2px;
        width: 10px;
        height: 10px;
        background-color: orangered;
        display: none;
      }
    }

    .video-list.active {
      .diyCheckBox {
        .point {
          display: inline-block;
        }
      }
    }
  }


</style>
